<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="/bootstrap.css">
    <style>
        .container {
            width: 500px;
            margin: 20px auto;
        }

        .add {
            width: 100%;
            height: 40px;
            font-size: 35px;
            text-align: center;
            line-height: 40px;

        }
        body{
            background:#ccc;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="add">信息修改</div>
        <p class="form-group">
            <label for="username">username:</label>
            <input type="text" name="username" class="form-control">
        </p>
        <p class="form-group">
            <label for="age">age:</label>
            <input type="text" name="age" class="form-control">
        </p>
        <p class="form-group">
            <input type="radio" name="sex" value="boy">boy
            <input type="radio" name="sex" value="girl">girl
        </p>
        <p class="form-group">
            <label for="phone">phone:</label>
            <input type="text" name="phone" class="form-control">
        </p>
        <p class="form-group">
            <input type="button" value="save" onclick="save()" class="btn btn-success">
            <a href="/sql.html">返回</a>
        </p>
    </div>
</body>
<script src="/jquery.min.js"></script>
<script>
    var id =location.hash.replace('#','');
     $.get('/users/find', {
            id:id 
        }).done(function (result) {
            console.log(result);
        $('[name="username"]').val(result.username)
        $('[name="age"]').val(result.age)
        $('[value="'+result.sex+'"]').prop('checked',true)
        $('[name=phone]').val(result.phone)
        })
       
    function save() {
        var username = $('[name="username"]').val()
        var age = $('[name="age"]').val()
        var sex = $('input:radio:checked').val()
        var phone = $('[name=phone]').val() 
        $.post('/users/edit',{
            username:username,
            age:age,
            id:id,
            sex:sex,
            phone:phone
        }).done(function(){
            location.href='/sql.html'
        })
    }
</script>

</html>